#include "smallwidget.h"
#include "ui_smallwidget.h"

#include <QSpinBox>
#include <QMessageBox>
SmallWidget::SmallWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SmallWidget)
{
    ui->setupUi(this);
//    ui->spinBox->value();
    ui->spinBox->setMaximum(100);
    ui->horizontalSlider->setMaximum(100);
    //发生重载,使用函数指针明确指向
  void(QSpinBox:: * signal)(int) =  &QSpinBox::valueChanged;
    connect(ui->spinBox,signal,ui->horizontalSlider,&QSlider::setValue);
    //反过来影响
    connect(ui->horizontalSlider,&QSlider::valueChanged,ui->spinBox,&QSpinBox::setValue);

}

SmallWidget::~SmallWidget()
{
    delete ui;
}

void SmallWidget::setValue(int v){
ui->horizontalSlider->setValue(v);
}

void SmallWidget::getValue(){
    QMessageBox::information(this,"获取值",QString::number(ui->horizontalSlider->value()));
}
void SmallWidget::setHalf(){
ui->horizontalSlider->setValue(ui->horizontalSlider->maximum()/2);
}
